var pageSize = 10;
$(document).ready(function(){
	//表格初始化
	initTable();
	//事件绑定
	eventBind();
});

function eventBind(){
	//带有分页信息的查询
	$("#queryBtn").click(pageQuery).click();
	$("#queryUnBtn").click(pageQuery).click();
}

function initTable(){
	$('#unReportTable').bootstrapTable({
		onPageChange: function (number, size) {
			pageSize = size;
			queryUn(number, size);
		},
		onCheck:function (row) {
			rowid=row.id;
			rowpid=row.patient_id;
		}
	});
	$('#reportTable').bootstrapTable({
		onPageChange: function (number, size) {
			pageSize = size;
			query(number, size);
		},
		onCheck:function (row) {
			rowid=row.id;
		}
	});
}

//带有分页信息的查询
function pageQuery(){
	queryUn(1, pageSize);
	query(1, pageSize);
};

//分页查询待报告
function queryUn(pageNumber, pageSize){
	var queryCondition={
		pageNumber: pageNumber, 
		pageSize: pageSize,
		params:$("#unReportForm").collect()
	}
	$.getApiClient('/register/listUReport').setQuery(queryCondition).post().done(function(data){
	    $('#unReportTable').bootstrapTable('load', data.payload);
	});
};

//分页查询已报告
function query(pageNumber, pageSize){
	var queryCondition={
		pageNumber: pageNumber, 
		pageSize: pageSize,
		params:$("#finishForm").collect()
	}
	$.getApiClient('/register/listReport').setQuery(queryCondition).post().done(function(data){
	    $('#reportTable').bootstrapTable('load', data.payload);
	});
};

//制定医生写报告
function showRegFormDialog(){
	if(rowid==null){//增加提示
		customTimeOutDialog('信息提示','请选择患者后进行操作',null,2000);
	}else{
		$.getApiClient('/transfer/agree/{id}/{pid}').setQuery({id:rowid,pid:rowpid}).post().done(function(data){
			if(data.code == "0"){
				BootstrapDialog.closeAll();
				customTimeOutDialog('信息提示','接诊成功',null,2000);
				pageQuery();
			}else{
				customAlertDialog(data.message, '错误提示', null, null);
			}
		});
	}
}

//写报告操作
function operateFormatter(value, row, index) {	
	var operates=[];
	operates.push('<a class="edit" href="javascript:void(0)" title="写报告"><i class="fa fa-edit"></i>写报告</a>');
	return operates.join('');
};

//查看操作
function viewoperateFormatter(value, row, index) {	
	var operates=[];
	operates.push('<a class="edit" href="javascript:void(0)" title="查看"><i class="fa fa-edit"></i>查看</a>');
	return operates.join('');
};

//写报告详细
operateEvents = {
   'click .edit' : function(e, value, row, index) {
		redirectCall('/page/business/remote/detail?type=write&id='+row.pid+"&rid="+row.id);
	}
};

// 查看详细
viewoperateEvents = {
	'click .edit' : function(e, value, row, index) {
		redirectCall('/page/business/remote/detail?type=view&id=' + row.pid + "&rid="+ row.id);
	}
};
